import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:riverpod_t/page/tabber/view/taber_page.dart' show TaberPage;
import 'package:riverpod_t/routers/routers.dart' show NovelRoutes;
import 'package:riverpod_t/until/app_util.dart';

/// 1.暗黑功能实现
/// 2.小说详情
/// 3.小说收藏案例
/// 4.车讯网列表
/// 6.点赞啥的局部刷新

void main() {
  runApp(const ProviderScope(child: MyHomePage()));
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

  @override
  void initState() {
    super.initState();
    NovelRoutes.initRoutes();
  }

  MaterialApp _materialApp(BuildContext context) {
    return MaterialApp(
      home: const TaberPage(),
      builder: (context, widget) {
        return MediaQuery(
          ///设置文字大小不随系统设置改变
          data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
          child: FlutterEasyLoading(child: widget),
        );
      },
      navigatorKey: AppUtil.navigatorKey,
      locale: const Locale('zh', 'CH'),
      localizationsDelegates: const [
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
      ],
      supportedLocales: const [Locale('zh', 'CH')],
      theme: ThemeData.light(), // 浅色主题
      darkTheme: ThemeData.dark(), // 暗色主题
    );
  }

  @override
  Widget build(BuildContext context) {
    return ScreenUtilInit(
      designSize: const Size(375, 812),
      minTextAdapt: true,
      builder: (BuildContext context, Widget? child) {
        return _materialApp(context);
      },
    );
  }
}
